home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / daytimeudp.rexx < prev    next >
OS/2 REXX Batch file  |  2000-11-28  |  1KB  |  59 lines

  1. /*
  2.     daytime udp client - Usage: daytimeudp host
  3.     daytime/udp client, to use with dtudpserv
  4.      or any daytime/udp server .
  5. */
  6.  
  7. if ~open("STDERR","*","W") then STDERR="STDOUT"
  8.  
  9. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  10. prg=ProgramName("NOEXT")
  11. if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then
  12.     call err "can't find" result,1
  13.  
  14. if ~RMH_ReadArgs("HOST/A") then do
  15.     call PrintFault()
  16.     exit
  17. end
  18.  
  19. remote.AddrAddr=resolve(parm.0.value)
  20. if remote.AddrAddr==-1 then call err "Host <"parm.0.value"> not found.",1
  21.  
  22. if GetServByName("se","daytime","udp") then
  23.     remote.AddrPort=se.ServPort
  24. else remote.AddrPort=13
  25.  
  26. sock=socket("inet","dgram")
  27. if sock<0 then call err "no socket"
  28.  
  29. call IOCtlSocket(sock,"fionbio",1)
  30. sig=2**AllocSignal()
  31. set.SigEventMask=sig
  32. call SetSocketBase("set")
  33. call SetSockOpt(sock,"socket","eventmask","error read")
  34.  
  35. if connect(sock,"remote")<0 then call err "connect error"
  36.  
  37. if send(sock,"A"x)~=1 then call err "send error"
  38.  
  39. wait.read.0=sock
  40. wait.ex.0=sock
  41. res=WaitSelect("wait",10,,sig)
  42.  
  43. if res<0 then call err "wait error"
  44. if res==0 & and(wait.signals,sig)==0 then call err "timeout",1
  45.  
  46. call GetSocketEvents("events")
  47. if events.error then call err "can't connect to" host
  48.  
  49. n=recv(sock,"buf")
  50. if len<0 then call "recv error"
  51. call WriteCH("STDOUT",buf)
  52. exit
  53.  
  54. err:
  55. parse arg msg,noerr
  56.     if noerr~=1 then msg = msg "("ErrorString()")"
  57.     call Writeln(stderr,prg": "msg)
  58.     exit
  59.